import unittest

from google.appengine.api import memcache
from google.appengine.ext import ndb
from google.appengine.ext import testbed

from server_main import *
from create_game_results import *
from statistics.word_statistic import *

json_string = '''
{
    "rounds": [
        {
            "words": [
                {
                    "text": "Word1",
                    "owner": "Owner",
                    "result": "GUESS",
                    "time": 5.6
                },
                {
                    "text": "Word2",
                    "owner": "Owner",
                    "result": "GUESS",
                    "time": 5.6
                }
            ],
            "player1": "Player_1",
            "player2": "Player_2"
        },
        {
            "words": [
                {
                    "text": "Word3",
                    "owner": "Owner",
                    "result": "FAIL",
                    "time": 5.6
                },
                {
                    "text": "Word4",
                    "owner": "Owner",
                    "result": "GUESS",
                    "time": 5.6
                }
            ],
            "player1": "Player_3",
            "player2": "Player_4"
        },

        {
            "words": [
                {
                    "text": "Word5",
                    "owner": "Owner",
                    "result": "GUESS",
                    "time": 5.6
                },
                {
                    "text": "Word6",
                    "owner": "Owner",
                    "result": "FAIL",
                    "time": 5.6
                }
            ],
            "player1": "Player_2",
            "player2": "Player_1"
        }
    ],
    "remote_id": 999
}
'''


class CGHTest(unittest.TestCase):
    def test_creation(self):
        self.game_history = json_to_game_history(json_string)
        self.results = gen_pair_results(self.game_history)
        self.assertEqual(self.results[0].player_1, "Player_2")
        self.assertEqual(self.results[0].player_2, "Player_1")
        self.assertEqual(self.results[0].first_explained, 1)
        self.assertEqual(self.results[0].first_guessed, 2)
        self.assertEqual(self.results[0].sum, 3)


if __name__ == '__main__':
    unittest.main()
